package cn.tedu.warehouse.controller;
import cn.tedu.warehouse.entity.*;
import cn.tedu.warehouse.page.Page;
import cn.tedu.warehouse.service.CheckService;
import cn.tedu.warehouse.service.InStoreService;

import cn.tedu.warehouse.service.StoreService;
import cn.tedu.warehouse.utils.CurrentUser;
import cn.tedu.warehouse.utils.TokenUtils;
import cn.tedu.warehouse.utils.WarehouseConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/check")
public class CheckController {

    @Autowired
    private CheckService checkService;


    //注入StoreService
    @Autowired
    private StoreService storeService;

    //注入TokenUtils
    @Autowired
    private TokenUtils tokenUtils;

    //注入InStoreService
    @Autowired
    private InStoreService inStoreService;

    /**
     * 添加盘点单的url接口/purchase/purchase-add
     */
    @RequestMapping("/check-add")
    public Result addCheck(@RequestBody Check check){
        log.debug("开始处理【添加盘点单】的请求，参数：{}",check);
        //执行业务
        Result result = checkService.savecheck(check);
        //响应
        return result;
    }

    /**
     * 查询所有仓库的url接口/purchase/store-list
     */
    @RequestMapping("/store-list")
    public Result storeList(){


        //执行业务
        List<Store> storeList = storeService.queryAllStore();
        //响应
        return Result.ok(storeList);
    }

    /**
     * 分页查询采购单的url接口/purchase/purchase-page-list
     *
     * 参数Page对象用于接收请求参数页码pageNum、每页行数pageSize;
     * 参数Purchase对象用于接收请求参数仓库id storeId、商品名称productName、
     * 采购人buyUser、是否生成入库单isIn、起止时间startTime和endTime;
     *
     * 返回值Result对象向客户端响应组装了所有分页信息的Page对象;
     */
    @RequestMapping("/check-page-list")
    public Result checkPageList(Page page, Check check){
        log.debug("开始处理【分页查询采购单】的请求，参数：{}",page);
        //执行业务
        page = checkService.queryCheckPage(page, check);
        //响应
        return Result.ok(page);
    }

    /**
     * 修改采购单的url接口/purchase/purchase-update
     *
     * @RequestBody Purchase purchase将请求传递的json数据封装到参数Purchase对象;
     */
    @RequestMapping("/check-update")
    public Result updateCheck(@RequestBody Check check){
        log.debug("开始处理【修改采购单】的请求，参数：{}",check);
        //执行业务
        Result result = checkService.updateCheck(check);
        //响应
        return result;
    }

    /**
     * 删除采购单的url接口/purchase/purchase-delete/{buyId}
     *
     * @PathVariable Integer buyId将路径占位符buyId的值赋值给参数变量buyId;
     */
    @RequestMapping("/check-delete/{checkId}")
    public Result deletecheck(@PathVariable Integer checkId){
        log.debug("开始处理【删除采购单】的请求，参数：{}",checkId);
        //执行业务
        Result result = checkService.deletecheck(checkId);
        //响应
        return result;
    }

    //导出数据
    @RequestMapping("/exportTable")
    public Result exportTable(Page page, Check check){
        log.debug("开始处理【导出数据】的请求，参数：{}",page);
        //分页查询商品
        page = checkService.queryCheckPage(page, check);
        //拿到当前页数据
        List<?> resultList = page.getResultList();
        //响应
        return Result.ok(resultList);
    }






}
